package com.ks.user.controller;


import com.ks.core.base._ControllerBase;
import com.ks.core.core.Result;
import com.ks.user.aop.Author;
import com.ks.user.controller.dto.LoginRequest;
import com.ks.user.controller.response.UserBaseDto;
import com.ks.user.entity.UserBase;
import com.ks.user.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-11-18
 */
@RestController
@RequestMapping("/sysUserBase")
@Api(value = "系统用户模块", description = "系统用户模块")
public class SysUserController extends _ControllerBase {

    @Autowired
    private ISysUserService sysUserService;

    @PostMapping("/login")
    @ApiOperation(value = "系统用户登录", notes = "系统用户登录")
    public Object Login(@RequestBody LoginRequest loginRequest) {
        Map<String, Object> login = sysUserService.login(loginRequest.getMobile(), loginRequest.getPassword(), loginRequest.getCode(), loginRequest.getUserName());
        return Result.success(login);
    }



    @Author
    @PostMapping("/signOut")
    @ApiOperation(value = "系统用户退出登录", notes = "系统用户退出登录")
    public Object SignOut() {
        int i = sysUserService.SignOut(getContext());
        return Result.success(i);
    }


    @PostMapping("/ResetPassword")
    @ApiOperation(value = "系统用户重置租户密码", notes = "系统用户重置租户密码")
    public Object ResetPassword(@RequestBody LoginRequest request) {
        int i = sysUserService.ResetPassword(request.getMobile());
        return Result.success(i);
    }

    @PostMapping("/updateSysUser")
    @ApiOperation(value = "系统用户修改个人信息详情接口", notes = "系统用户修改个人信息详情接口")
    public Object updateSysUser(@RequestBody UserBase userBase) {
        int i = sysUserService.updateSysUser(userBase.getId(), userBase.getINickName(), userBase.getINickName(), userBase.getIRealName(), userBase.getIEmail(), userBase.getIfavatar(), userBase.getISex(), userBase.getISign());
        return Result.success(i);
    }

    @PostMapping("/updateSysUserPwd")
    @ApiOperation(value = "系统用户修改个人密码接口", notes = "系统用户修改个人密码接口")
    public Object updateSysUserPwd(@RequestBody LoginRequest request) {
        int i = sysUserService.updateSysUserPwd(request.getUserId(), request.getPassword(), request.getNewPassword(), request.getMobile(), request.getCode());
        return Result.success(i);
    }

    @PostMapping("/querySysUserInfo")
    @ApiOperation(value = "系统用户获取个人信息接口", notes = "系统用户获取个人信息接口")
    public Object querySysUserInfo() {
        UserBaseDto userBaseDto = sysUserService.querySysUserInfo(getContext());
        return Result.success(userBaseDto);
    }


}

